package cn.aresoft.framework.exception;

public class ServiceException extends BaseException {

	public ServiceException(){
		super("ERR_AS_UNKNOWN");
	}
	
	public ServiceException(String errorCode) {
		super(errorCode);
	}
	
	public ServiceException(String errorCode,String[] msg) {
		super(errorCode);
		this.messageArray = msg;
	}
	
	public ServiceException(String errorCode, Throwable e) {
		super(errorCode, e);
		if(e instanceof ActionException){
			ActionException ae = (ActionException)e;
			this.setErrorCode(ae.getErrorCode());
			this.causeMessage = ae.getCauseMessage();
		}else{
			this.causeMessage = getCauseMessage(e);
		}
		
	}
	
	public ServiceException(String errorCode,String[] msg, Throwable e) {
		super(errorCode, e);
		this.messageArray = msg;
		this.causeMessage = getCauseMessage(e);
	}
	
	
	//store the message content from other system
	private String[] messageArray;
	private String causeMessage;

	
	private static String getCauseMessage(Throwable e ){
		if(e==null){
			return null;
		}else{
			return e.getMessage();
		}
	}
	
	public String[] getMessageArray() {
		return messageArray;
	}

	public String getCauseMessage() {
		return causeMessage;
	}
	
	public void setCauseMessage(String causeMessage) {
		this.causeMessage = causeMessage;
	}
	
	public void setMessageArray(String[] messageArray) {
		this.messageArray = messageArray;
	}
}
